﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "ValidatorImpl.h"
#include "SequenceValidator.h"
#include "DebugMessage.h"
#include "NumberValidator.h"
#include "SetValidator.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

namespace gcmp
{
    NumberValidatorImpl::NumberValidatorImpl()
        : m_opImpl(NEW_AS_OWNER_PTR(NumberValidator<double>))
    {
    }

    NumberValidatorImpl::NumberValidatorImpl(double minimum, double maximum, int decimals, const std::wstring& tooltip, bool minimumInclusive, bool maximumInclusive)
        : m_opImpl(NEW_AS_OWNER_PTR(NumberValidator<double>, minimum, maximum, tooltip, minimumInclusive, maximumInclusive, decimals))
    {
    }

    std::wstring NumberValidatorImpl::GetTooltip() const
    {
        DBG_WARN_AND_RETURN_UNLESS(m_opImpl, L"", L"数值校验器为空!",L"GDMPLab",L"2024-03-30");
        return m_opImpl->GetTip();
    }

    bool NumberValidatorImpl::SetTooltip(const std::wstring& tooltip)
    {
        DBG_WARN_AND_RETURN_FALSE_UNLESS(m_opImpl, L"数值校验器为空!",L"GDMPLab",L"2024-03-30");
        m_opImpl->SetTip(tooltip);
        return true;
    }

    bool NumberValidatorImpl::ValidateInput(const std::wstring& input) const
    {
        DBG_WARN_AND_RETURN_FALSE_UNLESS(m_opImpl, L"数值校验器为空!",L"GDMPLab",L"2024-03-30");
        return m_opImpl->ValidateInput(input);
    }

    SequenceValidatorImpl::SequenceValidatorImpl()
        : m_opImpl(NEW_AS_OWNER_PTR(SequenceValidator))
    {
    }

    SequenceValidatorImpl::SequenceValidatorImpl(int minimum, int maximum, int minCount, int maxCount, const std::wstring& tooltip)
        : m_opImpl(NEW_AS_OWNER_PTR(SequenceValidator, minimum, maximum, minCount, maxCount, tooltip))
    {
    }

    std::wstring SequenceValidatorImpl::GetTooltip() const
    {
        DBG_WARN_AND_RETURN_UNLESS(m_opImpl, L"", L"序列校验器为空!",L"GDMPLab",L"2024-03-30");
        return m_opImpl->GetTip();
    }

    bool SequenceValidatorImpl::SetTooltip(const std::wstring& tooltip)
    {
        DBG_WARN_AND_RETURN_FALSE_UNLESS(m_opImpl, L"序列校验器为空!",L"GDMPLab",L"2024-03-30");
        m_opImpl->SetTip(tooltip);
        return true;
    }

    bool SequenceValidatorImpl::ValidateInput(const std::wstring& input) const
    {
        DBG_WARN_AND_RETURN_FALSE_UNLESS(m_opImpl, L"序列校验器为空!",L"GDMPLab",L"2024-03-30");
        return m_opImpl->ValidateInput(input);
    }

    CollectionValidatorImpl::CollectionValidatorImpl()
        : m_opImpl(NEW_AS_OWNER_PTR(SetValidator<double>))
    {
    }

    CollectionValidatorImpl::CollectionValidatorImpl(const std::set<double>& collection, const std::wstring& tooltip)
        : m_opImpl(NEW_AS_OWNER_PTR(SetValidator<double>, collection, tooltip))
    {
    }

    std::wstring CollectionValidatorImpl::GetTooltip() const
    {
        DBG_WARN_AND_RETURN_UNLESS(m_opImpl, L"", L"集合校验器为空!",L"GDMPLab",L"2024-03-30");
        return m_opImpl->GetTip();
    }

    bool CollectionValidatorImpl::SetTooltip(const std::wstring& tooltip)
    {
        DBG_WARN_AND_RETURN_FALSE_UNLESS(m_opImpl, L"集合校验器为空!",L"GDMPLab",L"2024-03-30");
        m_opImpl->SetTip(tooltip);
        return true;
    }

    bool CollectionValidatorImpl::ValidateInput(const std::wstring& input) const
    {
        DBG_WARN_AND_RETURN_FALSE_UNLESS(m_opImpl, L"集合校验器为空!",L"GDMPLab",L"2024-03-30");
        return m_opImpl->ValidateInput(input);
    }

}
